package com.example.a313ldy.yuejian_17.Fragment.IndexFragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioGroup;
import com.example.a313ldy.yuejian_17.Bean.BannerView;
import com.example.a313ldy.yuejian_17.Fragment.IndexFragment.MasterFragment.MasterFragment;
import com.example.a313ldy.yuejian_17.R;
import java.util.ArrayList;
import java.util.List;



/**
 * Created by LDY on 2017/9/15.
 */

public class ChoicenessActivityFragment  extends Fragment {
    private RadioGroup radioGroup;
    private FragmentManager manager;
    private FragmentTransaction transaction;
    private Fragment mTab01;
    private Fragment mTab02;
    private Fragment mTab03;
    private int[] imgs = {R.drawable.a, R.drawable.b,R.drawable.c,R.drawable.d};
    private List<View> viewList;
    BannerView bannerView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.fragment_main, null) ;

        viewList = new ArrayList<View>();
        for (int i = 0; i < imgs.length; i++) {
            ImageView image = new ImageView(getContext());
            image.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            //设置显示格式
            image.setScaleType(ImageView.ScaleType.CENTER_CROP);
            image.setImageResource(imgs[i]);
            viewList.add(image);
        }
        bannerView = (BannerView) view.findViewById(R.id.banner);
        bannerView.startLoop(true);
        bannerView.setViewList(viewList);


        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        radioGroup = (RadioGroup) view.findViewById(R.id.main_tab_RadioGroup);
        manager = getChildFragmentManager();
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.index_activity:
                        mTab01 = new ActivitiesFragment();
                        replace(mTab01);
                        break;
                    case R.id.index_master:
                        mTab02 = new MasterFragment();
                        replace(mTab02);
                        break;
                    case R.id.index_match:
                        mTab03 = new ContestFragment();
                        replace(mTab03);
                        break;
                }

            }
        });

        radioGroup.check(R.id.index_activity);


}

    private void  replace(Fragment fragment){

        transaction=manager.beginTransaction();
        transaction.replace(R.id.id_content,fragment);
        transaction.commit();


    }


    public ChoicenessActivityFragment() {
    }
}